import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import Confirm from '#cpt/temp/Confirm'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 				= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))

const enabledData	= [{name:'未审核',value:'0'},{name:'审核通过',value:'1'},{name:'审核未通过',value:'-1'}]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			/* 绑定医院——按医院名称无法查询，输入框改下拉框 2021-08-16  --耿琰 */
			{ label: '医院名称',		name: 'hosp_id', type: 'select',nameStr:'name' },
			{ label: '医院代码',		name: 'hosp_code' },
			{ label: '医院条码',		name: 'hosp_spec' },
			{ label: '状态',		name: 'enabled', type:'select',data:enabledData },
		],
	}
	
	model = {}
	
	componentDidMount(){
		const { my_salesman_id, region_id } = $fn.query()
		this.query = { my_salesman_id, region_id, enabled:'' }
		this.getSelect()
		this.fetch()
	}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 医院名称
			$fn.setRow(forms, 'hosp_id', await f.getCache({ api:'bind_hospital' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'bs-hospital/index')
	
	// 表单
	cols = [
		{ title: '医院代码',		dataIndex: 'hosp_code', 	width:150 },
		{ title: '医院条码', 	dataIndex: 'hosp_spec', 	width:150},
		{ title: '医院名称', 	dataIndex: 'hosp_name', 	width:200 },
		{ title: '医院性质', 	dataIndex: 'nature_name', 	width:100 },
		{ title: '医院级别',		dataIndex: 'level_name', 	width:100 },
		{ title: '创建时间', 	dataIndex: 'create_at', 	...$fn.table.time},
		{ title: '状态', 		dataIndex: 'enabled', 		...$fn.table.status, render:text=>$fn.getState(enabledData,text) },
		{ title: '绑定状态', 	dataIndex: 'is_bind', 		...$fn.table.status },
	]
	// 操作按钮
	controls = () => [
		// 绑定
		Confirm.call(this, '绑定', 'bs-salesman/bindhosp',{isKeys:true, code:'F1',
			param: keys => ({salesman_id:this.query?.my_salesman_id,hosp_ids:keys})
		} ),
		// 解绑
		Confirm.call(this, '解绑', 'bs-salesman/untiehosp',{ idStr:'hosp_ids',isKeys:true, 
			param: keys => ({salesman_id:this.query?.my_salesman_id,hosp_ids:keys})
		 } ),
		// 返回
		Controls.back.call(this),	
	]
	
	render(){
		return (
			<>
				<Page title='绑定医院' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this) }
				</Page>
			</>
		)
	}
}

export default Index